package cn.lili.modules.promotion.entity.vos;

import cn.lili.common.utils.StringUtils;
import cn.lili.modules.promotion.entity.dos.BlindboxRule;
import cn.lili.modules.promotion.entity.dos.LiBlindboxRuleGoods;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @Author xiangqian
 * @Date 2023/10/4 16:05
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value = "盲盒规则")
@ToString(callSuper = true)
@NoArgsConstructor
public class BlindboxRuleVO extends BlindboxRule {

    /**
     * 规则商品
     * */
    List<LiBlindboxRuleGoods> goods;

    public BlindboxRuleVO(BlindboxRule blindboxRule) {
        if (blindboxRule == null) {
            return;
        }
        BeanUtils.copyProperties(blindboxRule, this);
    }

    public QueryWrapper<BlindboxRuleVO> queryWrapper(BlindboxRuleVO queryParam){
        QueryWrapper<BlindboxRuleVO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(queryParam.getRuleCode()),"rule_code",queryParam.getRuleCode());
        queryWrapper.like(StringUtils.isNotEmpty(queryParam.getRuleName()),"rule_name",queryParam.getRuleName());
        queryWrapper.eq(StringUtils.isNotEmpty(queryParam.getRuleType()),"rule_type",queryParam.getRuleType());
        queryWrapper.like(StringUtils.isNotEmpty(queryParam.getPrizeName()),"prize_name",queryParam.getPrizeName());
        queryWrapper.like(StringUtils.isNotEmpty(queryParam.getPrizeImage()),"prize_image",queryParam.getPrizeImage());
        queryWrapper.eq("delete_flag", false);
        queryWrapper.orderByDesc("create_time");
        return queryWrapper;
    }
}
